package org.luu.medicare.controller.commonController;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luu.medicare.common.Result;
import org.luu.medicare.entity.Company;
import org.luu.medicare.entity.PageBean;
import org.luu.medicare.entity.TDiagnosisProject;
import org.luu.medicare.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/company")
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CompanyController {
    private final CompanyService companyService;

    @DeleteMapping("/{id}")
    public Result<String> deleteById(@PathVariable Integer id) {
        log.info("公司 deleteById: {}", id);
        return companyService.deleteById(id);
    }

    @GetMapping("/{id}")
    public Result<Company> findById(@PathVariable Integer id) {
        log.info("公司 findById: {}", id);
        return companyService.findById(id);
    }

    @GetMapping()
    public Result<PageBean<Company>> page(@RequestParam(defaultValue = "1") int page,
                                                    @RequestParam(defaultValue = "10") int pageSize,
                                                    String name,
                                                    String id) {
        log.info("公司 page: {}, {}, {}, {}", page, pageSize, name, id);
        return companyService.page(page, pageSize, name, id);
    }

    @PostMapping
    public Result<String> save(@RequestBody Company company) {
        log.info("公司 save: {}", company);
        return companyService.save(company);
    }

    @PutMapping
    public Result<String> update(@RequestBody Company company) {
        log.info("公司 update: {}", company);
        return companyService.update(company);
    }
}
